package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {


    @Autowired
    private CategoryService categoryService;


    @GetMapping("/category/findAll")
    public ResultInfo findAll() {
        List<Category> list = categoryService.findAll();

        return ResultInfo.success(list);
    }


    @PostMapping("/category")
    public ResultInfo add(@RequestBody Category category) {
        categoryService.add(category);
        return ResultInfo.success(null);
    }


    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category){
        categoryService.update(category);
        return ResultInfo.success(null);
    }

    /*前端参数是  ？ 传参就不用@PathVariable注解
    *             /  restful风格
    * */
    @DeleteMapping("/category")
    public ResultInfo delete(Long id){
        categoryService.delete(id);
        return ResultInfo.success(null);
    }

    @GetMapping("/category/list")
    public ResultInfo findListByType(Integer type){
        List<Category> list = categoryService.findListByType(type);
        return ResultInfo.success(list);
    }

}
